import { Channel } from "./channel";
export const sendChannelMessage = (WindowName: any) => {
  Channel.send(Channel.channelEnum[WindowName].name, WindowName);
};
export const receiveChannelMessage = (callback: (message: string) => void) => {
  const handler = ({ data }) => {
    callback(data);
  };
  Object.keys(Channel.channelEnum).forEach((WindowName) => {
    Channel.listen(Channel.channelEnum[WindowName].name, handler);
  });
  return () => {
    Object.keys(Channel.channelEnum).forEach((WindowName) => {
      Channel.removeEvent(Channel.channelEnum[WindowName].name, handler);
      Channel.close(Channel.channelEnum[WindowName].name);
    });
  };
};
